
/**
 * 二维数组求包含所有1的最小矩形 
 * 求四个点即可
 */
class Solution {
public:
    int minimumArea(vector<vector<int>>& grid) {
        int n = grid.size();
        int m = grid[0].size();
        
        int top = 1E4, bottom = -1;
        int left = 1E4, right = -1;
        for(int i=0;i<n;++i)for(int j=0;j<m;++j){
            if(1 == grid[i][j]){
                top = min(top, i);
                bottom = max(bottom, i);
                left = min(left, j);
                right = max(right, j); 
            }
        }    

        return (right - left + 1) * (bottom - top + 1); 
    }
};